package com.lanqiao.attendance.handler.TeacherHandler;

import com.lanqiao.attendance.vo.LoginParam;
import com.lanqiao.attendance.vo.LoginParam2;
import com.lanqiao.attendance.vo.Result;
import com.lanqiao.attendance.vo.TeacherVo;
import org.apache.commons.codec.digest.DigestUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;


/**
 * * @Author Pu Yunsheng
 * * @Data 2022/7/11 下午 01:29
 * * @Version 1.0
 **/

@Aspect
@Component
public class SecretAop {

    @Around("@annotation(Secret)")
    public Result around(ProceedingJoinPoint joinPoint) throws Throwable {
        String salt = "shzu";
        Object[] args = joinPoint.getArgs();
        for (int i =0; i< args.length;i++) {
            if(args[i] instanceof TeacherVo){
                String tea_password = ((TeacherVo) args[i]).getPassword();
                String passwordMD5 = DigestUtils.md5Hex(tea_password+salt);
                ((TeacherVo) args[i]).setPassword(passwordMD5);
            }
            if(args[i] instanceof LoginParam2){
                String tea_password = ((LoginParam2) args[i]).getPassword();
                String passwordMD5 = DigestUtils.md5Hex(tea_password+salt);
                ((LoginParam2) args[i]).setPassword(passwordMD5);
            }
        }
        return (Result)joinPoint.proceed(args);
    }
}
